import { AssetService } from './../service/assetService'
import { BorrowingService } from './../service/borrowingService'
import { IncomeService } from './../service/incomeService'
// import { InvestmentService } from './../service/investmentService'
import { LiabilitiesService } from './../service/liabilitiesService'
import { NameTextService } from './../service/nameTextService'
import { SummaryService } from './../service/summaryService'
import { UserService } from './../service/userService'
import { LoginService } from './../service/loginService'
import { WindowService } from './../service/windowService'
export class Route {
  static routes: Array<RouteModel> = new Array<RouteModel>()
  static loadMapping() {
    this.GET('/netAssets', (params: any) => new AssetService().queryNetAssets(params), true)
    // asset
    this.GET('/asset', (params: any) => new AssetService().queryFundsList(params), true)
    this.GET('/asset/one', (params: any) => new AssetService().queryAsset(params), true)
    this.GET('/asset/count/mounth', (params: any) => new AssetService().countAssetByMonth(params), true)
    this.POST('/asset/upsert', (params: any) => new AssetService().upsertAsset(params), true)
    this.DELETE('/asset', (params: any) => new AssetService().deleteAsset(params), true)
    // liabilities
    this.GET('/liabilities', (params: any) => new LiabilitiesService().queryLiabilityList(params), true)
    this.POST('/liabilities/upsert', (params: any) => new LiabilitiesService().upsertLiability(params), true)
    this.DELETE('/liabilities', (params: any) => new LiabilitiesService().deleteLiability(params), true)
    // income
    this.GET('/income', (params: any) => new IncomeService().queryIncomeList(params), true)
    this.POST('/income/upsert', (params: any) => new IncomeService().upsertIncome(params), true)
    this.DELETE('/income', (params: any) => new IncomeService().deleteIncome(params), true)
    // borrowing
    this.GET('/borrowing', (params: any) => new BorrowingService().queryArrearsList(params), true)
    this.POST('/borrowing/upsert', (params: any) => new BorrowingService().upsertArrears(params), true)
    this.DELETE('/borrowing', (params: any) => new BorrowingService().deleteArrears(params), true)
    // investment
    // this.POST('/investment', (params: any) => new InvestmentService().queryInvestmentList(params), true)
    // this.POST('/investment/upsert', (params: any) => new InvestmentService().upsertInvestment(params), true)
    // this.DELETE('/investment', (params: any) => new InvestmentService().deleteInvestment(params), true)
    // nameText
    this.GET('/nameText', (params: any) => new NameTextService().queryNameTextList(params), true)
    this.POST('/nameText/upsert', (params: any) => new NameTextService().upsertNameText(params), true)
    this.DELETE('/nameText', (params: any) => new NameTextService().deleteNameText(params), true)
    // this.DELETE('/nameText/all',  (params: any) => new NameTextService().deleteAllNameText(params), true)
    // summary
    this.GET('/summary', (params: any) => new SummaryService().querySummary(params), true)
    // login
    this.GET('/checkEmail', (params: any) => new LoginService().checkEmail(params))
    this.POST('/registe', (params: any) => new LoginService().register(params))
    this.GET('/verify', (params: any) => new LoginService().verifyLogin(params))
    this.POST('/login', (params: any) => new LoginService().login(params))
    // user
    this.GET('/user/loginUser', (params: any) => new UserService().queryLoginUser(params), true)
    this.POST('/user/updatePassword', (params: any) => new UserService().updatePassword(params), true)
    this.POST('/user/update', (params: any) => new UserService().updateUser(params), true)
    //window
    this.POST('/window/mini', () => new WindowService().mini())
    this.POST('/window/expend', () => new WindowService().expend())
    this.POST('/window/close', () => new WindowService().close())
  }
  static GET(uri: string, caller: Function, isAuth?: boolean): void {
    this.map(uri, RequestMethod.get, caller, isAuth)
  }
  static PUT(uri: string, caller: Function, isAuth?: boolean): void {
    this.map(uri, RequestMethod.put, caller, isAuth)
  }
  static POST(uri: string, caller: Function, isAuth?: boolean): void {
    this.map(uri, RequestMethod.post, caller, isAuth)
  }
  static DELETE(uri: string, caller: Function, isAuth?: boolean): void {
    this.map(uri, RequestMethod.delete, caller, isAuth)
  }
  static map(uri: string, type: RequestMethod, method: Function, isAuth: boolean): void {
    if (!this.routes) {
      this.routes = new Array<RouteModel>({ uri: uri, method: type, caller: method, isAuth: isAuth })
    } else {
      this.routes.push({ uri: uri, method: type, caller: method, isAuth: isAuth })
    }
  }
}
export class RouteModel {
  uri: string
  method: RequestMethod
  caller: Function
  isAuth?: boolean
}
export enum RequestMethod {
  get,
  post,
  delete,
  put
}
